package com.jn.algorithm.day008.question25;

import java.util.Stack;

/**
 * @author 江南大学1033190417
 * @date 2022/4/22 21:12
 */
public class Solution {

    public ListNode reverseKGroup(ListNode head, int k) {
        ListNode pre = new ListNode(0);
        pre.next = head;
        ListNode temp = pre;


        return pre.next;
    }

    //翻转
    public ListNode reserve(ListNode node) {
        ListNode res = new ListNode(0);
        Stack<ListNode> stack = new Stack<>();
        while (node != null) {
            stack.push(node);
            node = node.next;
        }
        ListNode pre = res;
        while (!stack.isEmpty()) {

            pre.next = stack.pop();
            pre = pre.next;
        }
        return res.next;
    }


    public void print(ListNode node) {
        while (node != null) {
            System.out.print(node.val + "\t");
            node = node.next;
        }
    }

    public static void main(String[] args) {
        ListNode l1 = new ListNode(1);
        l1.next = new ListNode(4);
        l1.next.next = new ListNode(5);
        l1.next.next.next = new ListNode(3);
        Solution solution = new Solution();
        solution.print(l1);
        System.out.println();
        solution.print(solution.reserve(l1));
    }
}

class ListNode {
    int val;
    ListNode next;

    ListNode() {
    }

    ListNode(int val) {
        this.val = val;
    }

    ListNode(int val, ListNode next) {
        this.val = val;
        this.next = next;
    }
}
